//
//  RecommendViewController.m
//  Discover
//
//  Created by Hornby on 14-10-27.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "RecommendViewController.h"
#import "UIImageView+WebCache.h"
#import "NetHandler.h"
//#import "NewsTitle.h"
@interface RecommendViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain)UITableView *tableView;
@property (nonatomic, retain)NSMutableArray *array;
@property(nonatomic, retain)NSDictionary *dic1;
@end

@implementation RecommendViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.array = [NSMutableArray array];
        
    }
    return self;
}

- (void)startConnection
{
    [NetHandler netWorkWithURL:@"http://hotphone.myzaker.com/daily_hot_new.php?_appid=iphone&_bsize=640_960&_city=dalian&_province=19&_udid=BF7E602B-5431-401F-B710-133B46B47A2C&_uid=&_utoken=&_v=4.4.4&_version=4.51&act=pre&last_time=1414046488&rank=45000" completion:^(id result) {
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary:result];
        self.dic1 = [NSDictionary dictionaryWithDictionary:dic];
        
//        NSLog(@"%@",dic);
//        NSDictionary *dic1 = [dic objectForKey:@"data"];
//        NSMutableArray *dicarr = [NSMutableArray arrayWithArray:[dic1 objectForKey:@"articles"]];
//        for (NSDictionary *dic in dicarr) {
//            NewsTitle *newsTitle = [[NewsTitle alloc] initWithDictionary:dic];
//            [self.array addObject:newsTitle];
//            NSLog(@"%@", self.array);
//            [newsTitle release];
//            [self.tableView reloadData];
//        }
    }];

}

- (void)setUpView
{
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 70;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuse"] ;
    [self.view addSubview:self.tableView];
    [self.tableView release];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.0 green:0.7 blue:1.0 alpha:1];
    [self startConnection];
    [self setUpView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.array count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
//    NewsTitle *newsTitle = [self.array objectAtIndex:indexPath.row];
////    NewsTitle *newsTitle = [[NewsTitle alloc]initWithDictionary:_dic1];
//    NSLog(@"newsTitle:%@", newsTitle.title);
//    cell.textLabel.text = newsTitle.title;
    cell.textLabel.numberOfLines = 0;
    cell.textLabel.font = [UIFont systemFontOfSize:13];
      return cell;
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
